<?php
include_once("../includes/common.php");
include_once("../class/User.class.php");
include_once("../class/Explore.class.php");
include_once("../class/Comments.class.php");
include_once("../class/Sys.class.php");
require_once("../islogin.php");

if ($isadmin!=1){
    header('Location: /');
    exit('权限不足！');
}


$pageName = "首页";
$menuavatar = !$user_info["message"]["avatar"] ? "/data/avatar/default.jpg" : $user_info["message"]["avatar"];


$explore = new Explore();
$comments = new Comments();
$sys = new Sys();

$allnote_num = $explore->getAllNotes()["totalCount"];
//$alluser_num = $user->getAllUsers()["totalCount"];
$allcomments_num = $comments->getAllComments()["totalCount"];
$allstart_time = json_decode($sys->SysConfig(),true)["create_time"];

$days_difference = floor((time() - $allstart_time) / (60 * 60 * 24));

$user_ratio = json_decode($user->getUsersGender(),true);
//var_dump($user_ratio);

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <?php require_once('head.php'); ?>
</head> 
<body>
    
<!--==================== Preloader Start ====================-->
  <div class="preloader">
    <div class="loader"></div>
  </div>
<!--==================== Preloader End ====================-->

<!--==================== Sidebar Overlay End ====================-->
<div class="side-overlay"></div>
<!--==================== Sidebar Overlay End ====================-->


    <?php require_once('menu.php'); ?>

    <div class="dashboard-main-wrapper">


        <?php require_once('top_navbar.php'); ?>
        
        <div class="dashboard-body">

            <div class="row gy-4">
                <div class="col-xxl-8">
                    <div class="card h-100">
                        <div class="card-body grettings-box-two position-relative z-1 p-0">
                            <div class="row align-items-center h-100">
                                <div class="col-lg-6">
                                    <div class="grettings-box-two__content">
                                        <h3 class="fw-medium mb-0 flex-align gap-10">欢迎，管理员：<?php echo $user_info["message"]["nickname"];?>  <img src="/control/static/picture/wave-hand.png" alt=""> </h3>

                                        <h2 class="fw-medium mb-16"></h2>
                                        <p class="text-15 text-gray-400">本次登录IP：<?php echo long2ip($user_info["message"]["ip"]);?></p>

                                        <h2 class="fw-medium mb-16"></h2>
                                        <p class="text-15 text-gray-400">登录地区：<?php echo getIpProvince($user_info["message"]["ip"]);?></p>


                                    </div>
                                </div>
                                <div class="col-lg-6 d-md-block d-none mt-auto">
                                    <img src="/control/static/blue_bird/king.png" alt="">
                                </div>
                            </div>
                            <img src="/control/static/image/star-shape.png" class="position-absolute start-0 top-0 w-100 h-100 z-n1 object-fit-contain" alt="">
                        </div>
                    </div>
                </div>
                <div class="col-xxl-4">
                    <!-- Widgets Start -->
                    <div class="row gy-4">
                        <div class="col-sm-6">
                            <div class="card">
                                <div class="card-body text-center">
                                    <div class="flex-center gap-8 mb-24">
                                        <span class="flex-shrink-0 w-48 h-48 flex-center rounded-circle bg-main-600 text-white text-2xl"><i class="ph-fill ph-note"></i></span>
                                    </div>

                                    <h4 class="mb-2"><?php echo $allnote_num?> 篇</h4>
                                    <span class="text-gray-300">全站笔记</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="card">
                                <div class="card-body text-center">
                                    <div class="flex-center gap-8 mb-24">
                                        <span class="flex-shrink-0 w-48 h-48 flex-center rounded-circle bg-main-two-600 text-white text-2xl"><i class="ph-fill ph-users"></i></span>
                                    </div>

                                    <h4 class="mb-2"><?php echo $user_ratio['total']?> 位</h4>
                                    <span class="text-gray-300">全站用户</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="card">
                                <div class="card-body text-center">
                                    <div class="flex-center gap-8 mb-24">
                                        <span class="flex-shrink-0 w-48 h-48 flex-center rounded-circle bg-warning-600 text-white text-2xl"><i class="ph-fill ph-chat-centered-dots"></i></span>
                                    </div>

                                    <h4 class="mb-2"><?php echo $allcomments_num?> 条</h4>
                                    <span class="text-gray-300">全站评论</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="card">
                                <div class="card-body text-center">
                                    <div class="flex-center gap-8 mb-24">
                                        <span class="flex-shrink-0 w-48 h-48 flex-center rounded-circle bg-purple-600 text-white text-2xl"><i class="ph-fill ph-sun-dim"></i></span>
                                    </div>

                                    <h4 class="mb-2"><?php echo $days_difference?> 天</h4>
                                    <span class="text-gray-300">运行天数</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- Widgets End -->
                </div>
            </div>
            
            
            <div class="mt-24">
                <div class="row gy-4">
                    <div class="col-xxl-12">
                        <!-- Donut Chart Start -->
                        <div class="card h-100">
                            <div class="card-header border-bottom border-gray-100 flex-between gap-8 flex-wrap">
                                <h5 class="mb-0">全站性别比</h5>
                                <div class="dropdown flex-shrink-0">
                                    <button class="text-gray-400 text-xl d-flex rounded-4" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                        <i class="ph-fill ph-dots-three-outline"></i>
                                    </button>
                                    <div class="dropdown-menu dropdown-menu--md border-0 bg-transparent p-0">
                                        <div class="card border border-gray-100 rounded-12 box-shadow-custom">
                                            <div class="card-body p-12">
                                                <div class="max-h-200 overflow-y-auto scroll-sm pe-8">
                                                    <ul>
                                                        <li class="mb-0">
                                                            <a href="userlist.php" class="py-6 text-15 px-8 hover-bg-gray-50 text-gray-300 w-100 rounded-8 fw-normal text-xs d-block text-start">
                                                                <span class="text"> <i class="ph ph-book-open-user me-4"></i> 详情</span>
                                                            </a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="card-body">
                                <div class="flex-center mb-20">
                                    <div id="activityDonutChart" class="w-auto d-inline-block"></div>
                                </div>

                                <div class="flex-center gap-4 flex-wrap mt-20 justify-center">
                                    <div class="flex-center flex-column" style="margin-right: 100px">
                                        <span class="w-12 h-12 bg-white border border-3 border-main-600 rounded-circle"></span>
                                        <span class="text-13 my-4 text-main-600">男性</span>
                                        <h6 class="mb-0"><?php echo $user_ratio['male_ratio'];?>%</h6>
                                    </div>
                                    <div class="flex-center flex-column">
                                        <span class="w-12 h-12 bg-white border border-3 border-danger-600 rounded-circle"></span>
                                        <span class="text-13 my-4 text-danger-600">女性</span>
                                        <h6 class="mb-0"><?php echo $user_ratio['female_ratio'];?>%</h6>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- Donut Chart End -->
                    </div>

                </div>
            </div>
        </div>

        <?php require_once('footer.php'); ?>
    </div>
    <?php require_once('foot.php'); ?>
    <script>





        // =========================== Double Line Chart End ===============================

        // ============================ Donut Chart Start ==========================
        var options = {
            series: [<?php echo $user_ratio['male_ratio'];?>, <?php echo $user_ratio['female_ratio'];?>],
            chart: {
                height: 270,
                type: 'donut',
            },
            colors: ['#3D7FF9', '#EA5455'],
            enabled: true, // Enable data labels
            formatter: function (val, opts) {
                return opts.w.config.series[opts.seriesIndex] + '%';
            },
            dropShadow: {
                enabled: false
            },
            plotOptions: {
                pie: {
                    donut: {
                        size: '55%' // Fixed slice width
                    }
                }
            },
            responsive: [{
                breakpoint: 480,
                options: {
                    chart: {
                        width: "100%"
                    },
                    legend: {
                        show: false
                    }
                }
            }],
            legend: {
                position: 'right',
                offsetY: 0,
                height: 230,
                show: false
            }
        };

        var chart = new ApexCharts(document.querySelector("#activityDonutChart"), options);
        chart.render();
        // ============================ Donut Chart End ==========================
        
    </script>
    
    </body>
</html>